part of '../repository.dart';

class _AdminDto extends Equatable implements _UserDto {
  const _AdminDto._internal({
    required this.id,
    required this.email,
    required this.password,
  });

  @override
  final String id;

  @override
  final String email;

  @override
  final String password;

  @override
  UserRole get role => UserRole.admin;

  @override
  List<Object?> get props {
    return [
      id,
      email,
      password,
    ];
  }

  factory _AdminDto.fromJson(Map<String, dynamic> json) {
    return _AdminDto._internal(
      id: json[_kUserIdKey],
      email: json[_kUserEmailKey],
      password: json[_kUserPasswordKey],
    );
  }

  factory _AdminDto.fromEntity(Admin admin) {
    return _AdminDto._internal(
      id: admin.id,
      email: admin.email,
      password: admin.password,
    );
  }

  @override
  Map<String, dynamic> toJson() {
    final roleDto = _UserRoleDto.fromEntity(role);
    final roleString = roleDto.toString();

    return {
      _kUserIdKey: id,
      _kUserEmailKey: email,
      _kUserPasswordKey: password,
      _kUserRoleKey: roleString,
    };
  }

  @override
  Admin toEntity() {
    return Admin(
      id: id,
      email: email,
      password: password,
    );
  }
}
